#!/bin/bash

# Makes script exit on first non-zero error code
set -e

echo "### Run serverpod generate test"
echo "### If this test fails, make sure that you have run serverpod generate"
echo "### on all packages with util/run_tests_serverpod_generate"

# Install the serverpod command
echo "### Installing CLI tools"

export PATH="$PATH":"$HOME/.pub-cache/bin"

export SERVERPOD_HOME=$(pwd)
echo "### Serverpod home: $SERVERPOD_HOME"

# Verify that template directory exists
TEMPLATE_DIR="$SERVERPOD_HOME/templates/serverpod_templates"
echo "### Templates at: $TEMPLATE_DIR"
test -d $TEMPLATE_DIR

cd tools/serverpod_cli
dart pub global activate -s path .

cd $SERVERPOD_HOME

util/generate_all

util/ensure_no_changes
